#include<vector>
#include<deque>
#include<iostream>
using std::vector;
using std::deque;


class Solution {
public:
    vector<int> maxSlidingWindow(vector<int>& nums, int k) {
        deque<int> q;
        for (int i = 0; i < k; i++) {
            while (!q.empty() && nums[i] >= nums[q.back()]) {
                q.pop_back();
            }
            q.push_back(i);
        }

        vector<int> ans = {nums[q.front()]};
        for (int i = k; i < nums.size(); i++) {
            // insert new value
            while (!q.empty() && nums[i] > nums[q.back()]) q.pop_back();
            q.push_back(i);

            // pop old value
            while (!q.empty() && q.front() < i - k + 1) {
                q.pop_front();
            }
            // ans
            ans.push_back(nums[q.front()]);
        }
        return ans;
    }
};

int main() {
    int tmp;
    vector<int> input;
    while (std::cin >> tmp) {
        input.push_back(tmp);
    }
    for (auto n: input) {
        std::cout << n << " ";
    }
    std::cout << "\nResult is :\n";
    auto res = Solution().maxSlidingWindow(input, 3);
    for (auto n: res) {
        std::cout << n << " ";
    }
    std::cout << "\n";
    return 0;
}